﻿using System;
using System.Collections.Generic;
using SeaBattle.Domain.Entities;
using SeaBattle.Domain.Abstract;

namespace SeaBattle.Domain.Concrete
{
    public class FakeGameRepository : IGameRepository
    {
        /// <summary>
        /// fake game storage to avoid GC affects [by me] GC?
        /// </summary>
        private readonly List<Game> games = new List<Game>();

        private int GetNextId()
        {
            return games.Count+1;
        }

        /// <summary>
        /// creates new game instance with creator player specified
        /// </summary>
        /// <param name="creator">creator player</param>
        /// <returns>created game instance</returns>
        public Game CreateNewGame(Player creator)
        {
            return new Game(GetNextId(), DateTime.Now,creator);
        }

        /// <summary>
        /// save current game instance to the storage
        /// </summary>
        /// <param name="game">game instance</param>
        /// <returns>successful saving flag</returns>
        public bool SaveGame(Game game)
        {
            if(!games.Contains(game))
            {
                games.Add(game);
            }
            return true;
        }



    }
}
